package com.example.smartcity.ui.SmartCommynity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Adapter.CommunityBannerTitleAdapter;
import com.example.smartcity.ui.Adapter.RecommendShopAdapter;
import com.example.smartcity.ui.Adapter.RecycleViewAdapter;
import com.example.smartcity.ui.Adapter.ShopMessageAdapter;
import com.example.smartcity.ui.Bean.CommunityBannerBean;
import com.example.smartcity.ui.Bean.RealityManagementBean;
import com.example.smartcity.ui.Bean.ShopMessageBean;
import com.example.smartcity.ui.Bean.recommendBean;
import com.example.smartcity.ui.Bean.topicFunctionBean;
import com.example.smartcity.ui.Tools.BaseFragment;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.transformer.ZoomOutPageTransformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.zip.Inflater;

public class SmartCommunity extends Fragment {
    private Banner CommunityBanner;
    private Banner shopBanner;
    private RecyclerView RV_showFunction;
    private RecyclerView RV_shopMessage;
    private GridView GD_recommendShop;
    private View view;
    private static int[] icon = new int[]{
            R.drawable.wuyefuwu,
            R.drawable.kuaidi,
            R.drawable.shejioa,
            R.drawable.shangyetuiguang,
            R.drawable.mangercar
    };
    private static String titles[] = new String[]{
            "物业服务",
            "快件管理",
            "友邻社交",
            "商业推广",
            "车辆管理"
    };
    private static int[] hotel = new int[]{
      R.drawable.hotel_1,
       R.drawable.hotel_2,
       R.drawable.hotel_3,
       R.drawable.hotel_4,
       R.drawable.hotel_5,
       R.drawable.hotel_6,
    };
    ArrayList<Integer> list = new ArrayList<>();
    ArrayList<ShopMessageBean> ShopList = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.smartcommunity,container,false);
//        View view =LayoutInflater.from(getContext()).inflate(R.layout.smartcommunity,container,false);
        CommunityBanner = view.findViewById(R.id.CommunityBanner);
        RV_showFunction = view.findViewById(R.id.RV_showFunction);
        shopBanner = view.findViewById(R.id.shopBanner);
        RV_shopMessage = view.findViewById(R.id.shopMessage);
        GD_recommendShop = view.findViewById(R.id.GD_RecommendedShop);
        initView();
        return view;
    }
    public void initView(){
        setCommunityBanner();
        showFunction();
        setCommunityBanner();
        setShopBanner();
        setRV_shopMessage();
        setGD_recommendShop();
    }
    //加载广告Banner轮播
    public void setCommunityBanner(){
        CommunityBannerBean bean = new CommunityBannerBean();

        CommunityBannerBean.RowsBean bean1 = new CommunityBannerBean.RowsBean();
        List<CommunityBannerBean.RowsBean> beans1 = new ArrayList<>();
        bean1.setTitle("小区广告");
        bean1.setContent("苏果今日所有商品六折，欢迎各位业主前往抢购...");
        bean1.setPosition("苏果超市");
        bean1.setCreateTime("2021年04月12日");
        beans1.add(bean1);

        CommunityBannerBean.RowsBean bean2 = new CommunityBannerBean.RowsBean();
        bean2.setTitle("社区公告");
        bean2.setContent("社区工作人员今天在南门发放免费口罩，体温...");
        bean2.setPosition("社区公告");
        bean2.setCreateTime("2021年04月12日");
        beans1.add(bean2);

        CommunityBannerBean.RowsBean bean3 = new CommunityBannerBean.RowsBean();
        bean3.setTitle("公益广告");
        bean3.setContent("南京市第一人民医院今天在小区南门开放五常...");
        bean3.setPosition("人民医院");
        bean3.setCreateTime("2021年04月12日");
        beans1.add(bean3);

        bean.setRows(beans1);
        CommunityBannerTitleAdapter adapter = new CommunityBannerTitleAdapter(bean.getRows(),R.layout.communitybannernews);
        CommunityBanner.setAdapter(adapter).setOrientation(Banner.VERTICAL).setPageTransformer(new ZoomOutPageTransformer());
    }
    //加载功能展示
    public void showFunction(){
        ArrayList<topicFunctionBean> list = new ArrayList<>();
        for (int i = 0; i < icon.length; i++) {
            list.add(new topicFunctionBean(titles[i],icon[i]));
        }
        RecycleViewAdapter adapter = new RecycleViewAdapter(list,R.layout.topicefunctionitem);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        RV_showFunction.setLayoutManager(manager);
        RV_showFunction.setAdapter(adapter);
        //点击功能
        adapter.setOnItemClickListener(new RecycleViewAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void OnItemClickLister(int position) {
                switch (position){
                    case 0:
                        startActivity(new Intent(SmartCommunity.this.getContext(),RealtyManagement.class));
                        break;
                    case 1:
                        startActivity(new Intent(SmartCommunity.this.getContext(),ExpressManagement.class));
                        break;
                    case 3:
                        startActivity(new Intent(SmartCommunity.this.getContext(),CommercialPromotion.class));
                        break;
                    case 4:
                        startActivity(new Intent(SmartCommunity.this.getContext(),ManagerCar.class));
                        break;
                }
            }
        });
    }
    //商业推广
    public void setShopBanner(){
        list.add(R.drawable.shop_00);
        list.add(R.drawable.shop_01);
        list.add(R.drawable.shop_02);
        list.add(R.drawable.shop_03);
        list.add(R.drawable.shop_04);
        list.add(R.drawable.shop_05);
        shopBanner.setAdapter(new BannerImageAdapter<Integer>(list) {
            @Override
            public void onBindView(BannerImageHolder bannerImageHolder, Integer integer, int i, int i1) {
                bannerImageHolder.imageView.setImageResource(integer);
            }
        }).setBannerGalleryMZ(20).start().setIndicator(new CircleIndicator(getContext()));
    }
    //横向的RecycleView
    public void setRV_shopMessage(){
        ShopMessageBean b1 = new ShopMessageBean("#F06292","新货到店","满99减50");
        ShopMessageBean b2 = new ShopMessageBean("#DFCD8F","酒水大促","满99减50");
        ShopMessageBean b3 = new ShopMessageBean("#4DD0E2","美食速递","送货上门");
        ShopMessageBean b4 = new ShopMessageBean("#B968C7","一家包邮","购买方便");
        ShopList.add(b1);
        ShopList.add(b2);
        ShopList.add(b3);
        ShopList.add(b4);
        ShopMessageAdapter adapter = new ShopMessageAdapter(R.layout.shopmessageitem,ShopList);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        RV_shopMessage.setLayoutManager(manager);
        RV_shopMessage.setAdapter(adapter);
    }

    public void setGD_recommendShop(){
        ArrayList<recommendBean> list = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            list.add(new recommendBean(hotel[i],"红浪漫酒店","已售99间","￥199元"));
        }
        GD_recommendShop.setAdapter(new RecommendShopAdapter(R.layout.recommandshopitemlayout,list));
    }
}
